package ivan.cheng.activitys;

import ivan.cheng.R;
import ivan.cheng.utils.LogUtil;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.umeng.api.exp.UMSNSException;
import com.umeng.api.sns.UMSnsService;
import com.umeng.api.sns.UMSnsService.DataSendCallbackListener;
import com.umeng.api.sns.UMSnsService.RETURN_STATUS;
import com.umeng.api.sns.UMSnsService.SHARE_TO;

/**
 * 更多显示界面
 * 
 * @author tufei
 */
public class ShareActivity extends Activity implements OnClickListener
{
	private View mVInviteBySMS;
	private View mVInviteByEmail;
	private View mVInviteByWeibo;
	private View mVInviteByQQ;
	private TextView mTitle;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.share);
		mTitle = (TextView)findViewById(R.id.custom_title_txt);
		mTitle.setText(R.string.share_app_way);
		initViews();
	}

	private void initViews() {
		mVInviteBySMS = findViewById(R.id.share_by_sms);
		mVInviteBySMS.setOnClickListener(this);
		mVInviteByEmail = findViewById(R.id.share_by_email);
		mVInviteByEmail.setOnClickListener(this);
		mVInviteByWeibo = findViewById(R.id.share_by_sina);
		mVInviteByWeibo.setOnClickListener(this);
		mVInviteByQQ = findViewById(R.id.share_by_tx);
		mVInviteByQQ.setOnClickListener(this);
		
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.share_by_sms: 
		{
			Intent intent = new Intent(Intent.ACTION_VIEW);
			intent.putExtra("sms_body", getString(R.string.share_words_sms));
			intent.setType("vnd.android-dir/mms-sms");
			startActivity(intent);
		}
			break;
		case R.id.share_by_email: {
			Uri uri = Uri.parse("mailto:xxx@abc.com");
			Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
			intent.putExtra(Intent.EXTRA_SUBJECT,
					getString(R.string.share_words_email_title));
			intent
					.putExtra(
							Intent.EXTRA_TEXT,
							getString(R.string.share_words_sms));
			startActivity(Intent.createChooser(intent,
					getString(R.string.invite_words_choose_email)));
		}
			break;
		case R.id.share_by_sina: 
			UMSnsService.shareToSina(ShareActivity.this,
					getString(R.string.share_words_sms), new DataSendCallbackListener() 
			{
				@Override
				public void onDataSendFinished(RETURN_STATUS arg0, SHARE_TO arg1) 
				{
					LogUtil.d("RETURN_STATUS:"+arg0);
					LogUtil.d("SHARE_TO:"+arg1);
				}
				
				@Override
				public void onDataSendFailedWithException(UMSNSException arg0, SHARE_TO arg1) {
					LogUtil.w("RETURN_STATUS:"+arg0);
					LogUtil.w("SHARE_TO:"+arg1);
				}
			});
			break;
		case R.id.share_by_tx:  
			UMSnsService.shareToTenc(ShareActivity.this,
					getString(R.string.share_words_sms), new DataSendCallbackListener() 
					{
						@Override
						public void onDataSendFinished(RETURN_STATUS arg0, SHARE_TO arg1) 
						{
							LogUtil.d("RETURN_STATUS:"+arg0);
							LogUtil.d("SHARE_TO:"+arg1);
						}
						
						@Override
						public void onDataSendFailedWithException(UMSNSException arg0, SHARE_TO arg1) {
							LogUtil.w("RETURN_STATUS:"+arg0);
							LogUtil.w("SHARE_TO:"+arg1);
						}
					});
			break;
		default:
			break;
		}
	}
}
